namespace DotNetNuke.Entities.Modules.Actions
{
    using DotNetNuke.Security;
    using System;
    using System.Collections;
    using System.Reflection;
    using System.Runtime.InteropServices;

    /// -----------------------------------------------------------------------------
    /// Project		: DotNetNuke
    /// Class		: ModuleActionCollection
    /// -----------------------------------------------------------------------------
    /// <summary>
    /// Represents a collection of <see cref="T:DotNetNuke.ModuleAction" /> objects.
    /// </summary>
    /// <remarks>The ModuleActionCollection is a custom collection of ModuleActions.
    /// Each ModuleAction in the collection has it's own <see cref="P:DotNetNuke.ModuleAction.Actions" />
    /// collection which provides the ability to create a heirarchy of ModuleActions.</remarks>
    /// <history>
    /// [Joe] 	10/9/2003	Created
    /// </history>
    /// -----------------------------------------------------------------------------
    public class ModuleActionCollection : CollectionBase
    {
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new, empty instance of the <see cref="T:DotNetNuke.ModuleActionCollection" /> class.
        /// </summary>
        /// <remarks>The default constructor creates an empty collection of <see cref="T:DotNetNuke.ModuleAction" />
        /// objects.</remarks>
        /// <history>
        /// [Joe] 	10/9/2003	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public ModuleActionCollection()
        {
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="T:DotNetNuke.ModuleActionCollection" />
        /// class containing the elements of the specified source collection.
        /// </summary>
        /// <param name="value">A <see cref="T:DotNetNuke.ModuleActionCollection" /> with which to initialize the collection.</param>
        /// <remarks>This overloaded constructor copies the <see cref="T:DotNetNuke.ModuleAction" />s
        /// from the indicated collection.</remarks>
        /// <history>
        /// [Joe] 	10/9/2003	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public ModuleActionCollection(ModuleActionCollection value)
        {
            this.AddRange(value);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="T:DotNetNuke.ModuleActionCollection" />
        /// class containing the specified array of <see cref="T:DotNetNuke.ModuleAction" /> objects.
        /// </summary>
        /// <param name="value">An array of <see cref="T:DotNetNuke.ModuleAction" /> objects 
        /// with which to initialize the collection. </param>
        /// <remarks>This overloaded constructor copies the <see cref="T:DotNetNuke.ModuleAction" />s
        /// from the indicated array.</remarks>
        /// <history>
        /// [Joe] 	10/9/2003	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public ModuleActionCollection(ModuleAction[] value)
        {
            this.AddRange(value);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Add an element of the specified <see cref="T:DotNetNuke.ModuleAction" /> to the end of the collection.
        /// </summary>
        /// <param name="value">An object of type <see cref="T:DotNetNuke.ModuleAction" /> to add to the collection.</param>
        /// <returns>The index of the newly added <see cref="T:DotNetNuke.ModuleAction" /></returns>
        /// <history>
        /// [Joe] 	10/9/2003	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public int Add(ModuleAction value)
        {
            return this.List.Add(value);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Add an element of the specified <see cref="T:DotNetNuke.ModuleAction" /> to the end of the collection.
        /// </summary>
        /// <param name="ID">This is the identifier to use for this action.</param>
        /// <param name="Title">This is the title that will be displayed for this action</param>
        /// <param name="CmdName">The command name passed to the client when this action is 
        /// clicked.</param>
        /// <param name="CmdArg">The command argument passed to the client when this action is 
        /// clicked.</param>
        /// <param name="Icon">The URL of the Icon to place next to this action</param>
        /// <param name="Url">The destination URL to redirect the client browser when this 
        /// action is clicked.</param>
        /// <param name="UseActionEvent">Determines whether client will receive an event
        /// notification</param>
        /// <param name="Secure">The security access level required for access to this action</param>
        /// <param name="Visible">Whether this action will be displayed</param>
        /// <returns>The index of the newly added <see cref="T:DotNetNuke.ModuleAction" /></returns>
        /// <remarks>This method creates a new <see cref="T:DotNetNuke.ModuleAction" /> with the specified
        /// values, adds it to the collection and returns the index of the newly created ModuleAction.</remarks>
        /// <history>
        /// [Joe] 	10/18/2003	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public ModuleAction Add(int ID, string Title, string CmdName, [Optional, DefaultParameterValue("")] string CmdArg, [Optional, DefaultParameterValue("")] string Icon, [Optional, DefaultParameterValue("")] string Url, [Optional, DefaultParameterValue(false)] bool UseActionEvent, [Optional, DefaultParameterValue((SecurityAccessLevel)(-1))] SecurityAccessLevel Secure, [Optional, DefaultParameterValue(true)] bool Visible, [Optional, DefaultParameterValue(false)] bool NewWindow)
        {
            return this.Add(ID, Title, CmdName, CmdArg, Icon, Url, "", UseActionEvent, Secure, Visible, NewWindow);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Add an element of the specified <see cref="T:DotNetNuke.ModuleAction" /> to the end of the collection.
        /// </summary>
        /// <param name="ID">This is the identifier to use for this action.</param>
        /// <param name="Title">This is the title that will be displayed for this action</param>
        /// <param name="CmdName">The command name passed to the client when this action is 
        /// clicked.</param>
        /// <param name="CmdArg">The command argument passed to the client when this action is 
        /// clicked.</param>
        /// <param name="Icon">The URL of the Icon to place next to this action</param>
        /// <param name="Url">The destination URL to redirect the client browser when this 
        /// action is clicked.</param>
        /// <param name="ClientScript">Client side script to be run when the this action is 
        /// clicked.</param>
        /// <param name="UseActionEvent">Determines whether client will receive an event
        /// notification</param>
        /// <param name="Secure">The security access level required for access to this action</param>
        /// <param name="Visible">Whether this action will be displayed</param>
        /// <returns>The index of the newly added <see cref="T:DotNetNuke.ModuleAction" /></returns>
        /// <remarks>This method creates a new <see cref="T:DotNetNuke.ModuleAction" /> with the specified
        /// values, adds it to the collection and returns the index of the newly created ModuleAction.</remarks>
        /// ''' <history>
        /// [jbrinkman]	5/22/2004	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public ModuleAction Add(int ID, string Title, string CmdName, string CmdArg, string Icon, string Url, string ClientScript, bool UseActionEvent, SecurityAccessLevel Secure, bool Visible, bool NewWindow)
        {
            ModuleAction ModAction = new ModuleAction(ID, Title, CmdName, CmdArg, Icon, Url, ClientScript, UseActionEvent, Secure, Visible, NewWindow);
            this.Add(ModAction);
            return ModAction;
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Adds the contents of another <see cref="T:DotNetNuke.ModuleActionCollection" />
        /// to the end of the collection.
        /// </summary>
        /// <param name="value">A <see cref="T:DotNetNuke.ModuleActionCollection" /> containing 
        /// the objects to add to the collection. </param>
        /// <history>
        /// [Joe] 	10/9/2003	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public void AddRange(ModuleActionCollection value)
        {
            IEnumerator refObjectHelperL0=null;
            try
            {
                refObjectHelperL0 = value.GetEnumerator();
                while (refObjectHelperL0.MoveNext())
                {
                    ModuleAction mA = (ModuleAction) refObjectHelperL0.Current;
                    this.Add(mA);
                }
            }
            finally
            {
                if (refObjectHelperL0 is IDisposable)
                {
                    (refObjectHelperL0 as IDisposable).Dispose();
                }
            }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Copies the elements of the specified <see cref="T:DotNetNuke.ModuleAction" />
        /// array to the end of the collection.
        /// </summary>
        /// <param name="value">An array of type <see cref="T:DotNetNuke.ModuleAction" />
        /// containing the objects to add to the collection.</param>
        /// <history>
        /// [Joe] 	10/9/2003	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public void AddRange(ModuleAction[] value)
        {
            int refIntHelperL0 = value.Length - 1;
            for (int i = 0; i <= refIntHelperL0; i++)
            {
                this.Add(value[i]);
            }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets a value indicating whether the collection contains the specified <see cref="T:DotNetNuke.ModuleAction" />.
        /// </summary>
        /// <param name="value">The <see cref="T:DotNetNuke.ModuleAction" /> to search for in the collection.</param>
        /// <returns><b>true</b> if the collection contains the specified object; otherwise, <b>false</b>.</returns>
        /// <example>
        /// <code>
        /// ' Tests for the presence of a ModuleAction in the 
        /// ' collection, and retrieves its index if it is found.
        /// Dim testModuleAction = New ModuleAction(5, "Edit Action", "Edit")
        /// Dim itemIndex As Integer = -1
        /// If collection.Contains(testModuleAction) Then
        /// itemIndex = collection.IndexOf(testModuleAction)
        /// End If
        /// </code>
        /// </example>
        /// <history>
        /// [Joe] 	10/9/2003	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public bool Contains(ModuleAction value)
        {
            return this.List.Contains(value);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets the index in the collection of the specified <see cref="T:DotNetNuke.ModuleActionCollection" />, 
        /// if it exists in the collection.
        /// </summary>
        /// <param name="value">The <see cref="T:DotNetNuke.ModuleAction" /> to locate in the collection.</param>
        /// <returns>The index in the collection of the specified object, if found; otherwise, -1.</returns>
        /// <example> This example tests for the presense of a ModuleAction in the
        /// collection, and retrieves its index if it is found.
        /// <code>
        /// Dim testModuleAction = New ModuleAction(5, "Edit Action", "Edit")
        /// Dim itemIndex As Integer = -1
        /// If collection.Contains(testModuleAction) Then
        /// itemIndex = collection.IndexOf(testModuleAction)
        /// End If
        /// </code>
        /// </example>
        /// <history>
        /// [Joe] 	10/9/2003	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public int IndexOf(ModuleAction value)
        {
            return this.List.IndexOf(value);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Add an element of the specified <see cref="T:DotNetNuke.ModuleAction" /> to the 
        /// collection at the designated index.
        /// </summary>
        /// <param name="index">An <see cref="T:system.int32">Integer</see> to indicate the location to add the object to the collection.</param>
        /// <param name="value">An object of type <see cref="T:DotNetNuke.ModuleAction" /> to add to the collection.</param>
        /// <example>
        /// <code>
        /// ' Inserts a ModuleAction at index 0 of the collection. 
        /// collection.Insert(0, New ModuleAction(5, "Edit Action", "Edit"))
        /// </code>
        /// </example>
        /// <history>
        /// [Joe] 	10/9/2003	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public void Insert(int index, ModuleAction value)
        {
            this.List.Insert(index, value);
        }

        /// ----------------------------------------------------------------------------- 
        /// <summary>
        /// Remove the specified object of type <see cref="T:DotNetNuke.ModuleAction" /> from the collection.
        /// </summary>
        /// <param name="value">An object of type <see cref="T:DotNetNuke.ModuleAction" /> to remove from the collection.</param>
        /// <example>
        /// <code>
        /// ' Removes the specified ModuleAction from the collection. 
        /// Dim testModuleAction = New ModuleAction(5, "Edit Action", "Edit")
        /// collection.Remove(testModuleAction)
        /// </code>
        /// </example>
        /// <history>
        /// [Joe] 	10/9/2003	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public void Remove(ModuleAction value)
        {
            this.List.Remove(value);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets or sets the <see cref="T:DotNetNuke.ModuleActionCollection" /> at the 
        /// specified index in the collection.
        /// <para>
        /// In VB.Net, this property is the indexer for the <see cref="T:DotNetNuke.ModuleActionCollection" /> class.
        /// </para>
        /// </summary>
        /// <param name="index">The index of the collection to access.</param>
        /// <value>A <see cref="T:DotNetNuke.ModuleAction" /> at each valid index.</value>
        /// <remarks>This method is an indexer that can be used to access the collection.</remarks>
        /// <history>
        /// [Joe] 	10/9/2003	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public ModuleAction this[int index]
        {
            get
            {
                return (ModuleAction) this.List[index];
            }
            set
            {
                this.List[index] = value;
            }
        }
    }
}

